package com.xiaotu.controller;

import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
import com.xiaotu.common.BaseController;
import com.xiaotu.service.PlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhangxiao
 * @create 2022-03-11 15:18
 */
@RequestMapping("player")
@RestController
@CrossOrigin
public class PlayerController extends BaseController {

    @Autowired
    private PlayerService playerService;

    /**
     * 获取玩家信息
     */
    @GetMapping("getPlayerInfo")
    public Object getPlayerInfo(HttpServletRequest request) {
        return playerService.getPlayerInfo(getPlayerId(request));
    }

    /**
     * 换头像
     *
     * @param playerId
     * @param imageId
     */
    @PostMapping("changeImage")
    public Object changeImage(Integer playerId, Integer imageId) {
        Validator.validateTrue(ObjectUtil.isNotNull(playerId), "playerId 不能为空");
        Validator.validateTrue(ObjectUtil.isNotNull(imageId), "imageId 不能为空");
        playerService.changeImage(playerId, imageId);
        return null;
    }

}
